package top.zhangjianyong.tools.boss;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ： zhangjianyong
 * @date ： 2023/8/1 15:15
 */
public class JobList {

    public static void main(String[] args) {
        int page = 0;
        int size = 30;
        String url = "https://www.zhipin.com/wapi/zpgeek/search/joblist.json" +
                "?scene=1&query=java&city=101210600&experience=&payType=&partTime=&degree=&industry=&scale=&stage=" +
                "&position=100101&jobType=&salary=&multiBusinessDistrict=&multiSubway=" +
                "&page=" + page +
                "&pageSize=" + size;

        List list = new ArrayList();
        while (true) {
            HttpRequest get = HttpUtil.createGet(url);
            get.cookie("wd_guid=865725d6-93c4-4011-8b8d-82ea9b8dfe77; historyState=state; lastCity=101210600; __g=-; __l=l=%2Fwww.zhipin.com%2Fchengshi%2Fc101210600%2F&r=&g=&s=3&friend_source=0; Hm_lvt_194df3105ad7148dcf2b98a91b5e727a=1690873596; Hm_lpvt_194df3105ad7148dcf2b98a91b5e727a=1690873656; __c=1690873596; __a=36091010.1679970863.1679970863.1690873596.11.2.2.11; _bl_uid=Lel0Rkt6rF1ywLismo7ja049OtOF; __zp_stoken__=013dePDkkVBwPA2NiQCMfAwoDdGI%2FbigWBEQReGYCBiNgKjw7PnRJcnlREH1EbCgFTy4JJAp7PnIGVRM8FmAgEGZaLCN1VCwUDSAxczITU0dvSU1iEFEsASINPRJmVXhODRc7W3sAVAVRRx0%3D");
            HttpResponse execute = get.execute();
            String body = execute.body();
            JSONObject object = JSONObject.parseObject(body);
            JSONObject zpData = object.getJSONObject("zpData");
            JSONArray jobList = zpData.getJSONArray("jobList");
            if (jobList==null) break;
            list.addAll(jobList);
            page++;
            if (jobList.size() != 30) break;
        }
        System.out.println(list.size());


    }
}
